clear all 
set more off
cd "/Users/yasenov/Dropbox/mariel_boatlift/jhr_version/jhr_figures"
global folder /Users/yasenov/Dropbox/mariel_boatlift/revision_version/revision_data/

tempfile table3

use fig2a, clear
rename (_time _Y_treated _Y_synthetic) (year fig2a1 fig2a0)
keep year fig2a1 fig2a0
keep if year != .
saveold `table3'.dta, replace

use fig2b, clear
rename (_time _Y_treated _Y_synthetic) (year fig2b1 fig2b0)
keep year fig2b1 fig2b0
keep if year != .
merge 1:1 year using `table3'.dta, nogenerate
saveold `table3'.dta, replace

use fig2c, clear
rename (_time _Y_treated _Y_synthetic) (year fig2c1 fig2c0)
keep year fig2c1 fig2c0
keep if year != .
merge 1:1 year using `table3'.dta, nogenerate
saveold `table3'.dta, replace

use fig3a, clear
rename (_time _Y_treated _Y_synthetic) (year fig3a1 fig3a0)
keep year fig3a1 fig3a0
keep if year != .
merge 1:1 year using `table3'.dta, nogenerate
saveold `table3'.dta, replace

use fig3d, clear
rename (year logearnwke_mia logearnwke_card) (year fig3d1 fig3d0)
keep year fig3d1 fig3d0
keep if year != .
merge 1:1 year using `table3'.dta, nogenerate
saveold `table3'.dta, replace

use fig2d, clear
rename (_time _Y_treated _Y_synthetic) (year fig2d1 fig2d0)
keep year fig2d1 fig2d0
keep if year != .
merge 1:1 year using `table3'.dta, nogenerate
saveold `table3'.dta, replace

**********
**********

reshape long fig2a fig2b fig2c fig3a fig3d fig2d, i(year) j(city)

drop if year == 1980

label define citylabel 1 "Miami"
label define citylabel 0 "Synthetic", add
label values city citylabel

gen mia = city == 1
gen synthetic = city == 0


gen pre1 = year >=1976 & year <=1978
gen pre2 = year >=1972 & year <=1975
gen post1 = year >=1981 & year <=1982
gen post2 = year >=1983 & year <=1985
gen post3 = year >=1986 & year <=1988
gen post4 = year >=1989 & year <=1991

gen miapre1 = mia*pre1
gen miapre2 = mia*pre2
gen miapost1 = mia*post1
gen miapost2 = mia*post2
gen miapost3 = mia*post3
gen miapost4 = mia*post4

label var miapre1 "Mia X '76-'78"
label var miapre2 "Mia X '72-'75"
label var miapost1 "Mia X '81-'82"
label var miapost2 "Mia X '83-'85"
label var miapost3 "Mia X '86-'88"
label var miapost4 "Mia X '89-'91"

* Table with AR1 error structure *
xtset city year

xtgls fig2a miapre* miapost* i.year i.city, corr(ar1) force
estimates store fig2a

xtgls fig2b miapre* miapost* i.year i.city, corr(ar1) force
estimates store fig2b

xtgls fig2c miapre* miapost* i.year i.city, corr(ar1) force
estimates store fig2c

xtgls fig3a miapre* miapost* i.year i.city, corr(ar1) force
estimates store fig3a

xtgls fig3d miapre* miapost* i.year i.city, corr(ar1) force
estimates store fig3d

xtgls fig2d miapre* miapost* i.year i.city, corr(ar1) force
estimates store fig2d

estimates table fig2a fig2b fig2c fig3a fig3d fig2d, ///
	keep(miapre2 miapre1 miapost1 miapost2 miapost3 miapost4) ///
	b(%4.3f) se(%4.3f) stats(r2 N) varlabel

estimates table fig2a fig2b fig2c fig3a fig3d fig2d, ///
	keep(miapre2 miapre1 miapost1 miapost2 miapost3 miapost4) ///
	b(%4.3f) star stats(r2 N) varlabel
